error.spec.js ➔ ???   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 7
Bugs 0 Features 2
Metric Value
cc 1
c 7
b 0
f 2
nc 1
dl 0
loc 4
rs 10
nop 1
1
import test from 'ava';
2
import APIError from '../src/error';
3
4
test.beforeEach(t => {
5
    t.context.error = new APIError(404, 'Not Found', { body: 'body'});
6
    t.context.errorNoMessage = new APIError(404);
7
});
8
9
test('instance of Error', t => {
10
    t.true(t.context.error instanceof Error);
11
});
12
13
test('instance of APIError', t => {
14
    t.true(t.context.error instanceof APIError);
15
});
16
17
test('to string', t => {
18
    t.is(t.context.error.toString(), '404 - Not Found', 'has message');
19
    t.is(t.context.errorNoMessage.toString(), '404', 'No message');
20
});
21
22
test('has correct attributes', t => {
23
    t.is(t.context.error.code, 404);
24
    t.is(t.context.error.message, 'Not Found');
25
    t.deepEqual(t.context.error.body, { body: 'body'});
26
});